package com.bnyy.medicalHousekeeper.moudle.message.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import androidx.activity.result.ActivityResultLauncher;

import com.bnyy.medicalHousekeeper.R;
import com.bnyy.medicalHousekeeper.base.BaseActivityImpl;
import com.bnyy.medicalHousekeeper.request.BaseObserverImpl;
import com.bnyy.medicalHousekeeper.request.RequestManager;
import com.bnyy.message.bean.GroupChatVote;

import java.util.HashMap;

import butterknife.BindView;

/**
 * Author : 关炳鹏
 * Description :
 * Date : 2023/1/5
 **/
public class GroupChatActivityCreateActivity extends BaseActivityImpl {
    @BindView(R.id.et_title)
    EditText etTitle;
    @BindView(R.id.tv_confirm)
    TextView tvConfirm;

    private int dp12;

    public static void show(Context context, int groupChatId, ActivityResultLauncher<Intent> launcher) {
        Intent intent = new Intent(context, GroupChatActivityCreateActivity.class);
        intent.putExtra("groupChatId", groupChatId);
        launcher.launch(intent);
    }

    @Override
    public int getLayoutId() {
        return R.layout.activity_create_group_chat_activity;
    }

    @Override
    public String getTitleStr() {
        return "发布活动";
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        tvConfirm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (TextUtils.isEmpty(etTitle.getText())) {
                    Toast.makeText(mContext, "请输入主题", Toast.LENGTH_SHORT).show();
                    return;
                }

                HashMap<String, Object> params = new HashMap<>();
                params.put("id", getIntent().getIntExtra("groupChatId", 0));
                params.put("subject", etTitle.getText().toString());

                requestManager.request(requestManager.mMessageRetrofitService.createGroupChatActivity(RequestManager.getJsonRequestBody(params)),
                        new BaseObserverImpl<GroupChatVote>(mContext) {
                            @Override
                            public void onSuccess(GroupChatVote groupChatVote) {
                                super.onSuccess(groupChatVote);
                                setResult(RESULT_OK);
                                finish();
                            }
                        });
            }
        });
    }
}







































